package com.looookme.shaozhuo.msg;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.looookme.shaozhuo.mb_study.MainActivity;
import com.looookme.shaozhuo.mb_study.R;

/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class Msg_Notification extends Activity {
    public NotificationManager nManager = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        initView();
    }

    private static final int NOTIFYID_1  = 120;
    private static final int NOTIFYID_2  = 121;
    private void initView() {
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        setContentView(linearLayout);

        Button showBtn = new Button(this);
        showBtn.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        showBtn.setText("显示通知");
        linearLayout.addView(showBtn);
        showBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //普通Notification
                Notification notify = new NotificationCompat.Builder(Msg_Notification.this)
                        .setSmallIcon(R.drawable.item_icon)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ball))
                        .setTicker("ShowNormal")
                        .setContentInfo("ContentInfo")
                        .setContentTitle("ContentTitle")
                        .setContentText("ContentText")
                        .setNumber(1)
                        .setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setContentIntent(PendingIntent.getActivity(Msg_Notification.this, 0, new Intent(Msg_Notification.this, MainActivity.class), 0))
                        .build();
                nManager.notify(NOTIFYID_1, notify);
            }
        });

        Button delBtn = new Button(this);
        delBtn.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        delBtn.setText("删除通知");
        linearLayout.addView(delBtn);
        delBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                nManager.cancel(NOTIFYID_1);

                nManager.cancelAll();
            }
        });
    }
}
